package com.jrx.anytxn.transaction.controller.cms;


import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.i18n.response.TxnPage;
import com.jrx.anytxn.i18n.response.TxnRespResult;
import com.jrx.anytxn.transaction.dto.interfaceinfo.GlInterfaceInfoRes;
import com.jrx.anytxn.transaction.service.IGlInterfaceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jrx.auth.filter.service.InfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName GlInterfaceInfo
 *  与页面相关的总账流水表管理api接口
 * @author  yf
 * date  2019/9/9 0009
 * @Version V1.0
 **/
@Api(tags = "与页面相关的总账流水表管理api接口")
@RestController
@RequestMapping("/transaction/glInterfaceInfo")
public class GlInterfaceInfoController {

    private static final Logger logger = LoggerFactory.getLogger(GlInterfaceInfoController.class);

    @Autowired
    private IGlInterfaceService glInterfaceService;

    @Resource
    private InfoService infoService;

    @ApiOperation("分页查询总账流水表信息")
    @GetMapping("/pageNum/{pageNum}/pageSize/{pageSize}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "页大小", required = true),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true)})
    public TxnRespResult<TxnPage<GlInterfaceInfoRes>> getAllGlInterfaceInfoByPage(@PathVariable(value = "pageNum") Integer pageNum, @PathVariable(value = "pageSize") Integer pageSize, @RequestParam("customerId") String customerId,@RequestParam("loanId") String loanId) {
        logger.debug("分页查询总账流水表信息：开始");
        TxnRespResult<TxnPage<GlInterfaceInfoRes>> result = new TxnRespResult<>();
        try {
            String tenantId=String.valueOf(infoService.getUser().getProjectId());
            result.getSuccess(glInterfaceService.getGlInterfaceInfoByPage(tenantId,pageNum, pageSize,customerId,loanId));
            logger.debug("分页查询总账流水表信息：结束");
        } catch (TxnException e) {
            logger.error("分页查询总账流水表信息:{}", e);
            result.getFail(e.getErrCode(), e.getErrMsg());
        }
        return result;
    }

    @ApiOperation("通过主键查询总账流水表信息")
    @GetMapping("/{id}/{tenantId}/{customerId}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = true),
            @ApiImplicitParam(name = "tenantId", value = "租戶id", required = true),
            @ApiImplicitParam(name = "customerId", value = "客戶id", required = true)})
    public TxnRespResult<GlInterfaceInfoRes> getGlInterfaceInfoByPrimaryKey(@PathVariable(value = "id") Long id,@PathVariable(value = "tenantId") String tenantId,@PathVariable(value = "customerId") String customerId) {
        logger.debug("通过主键查询总账流水表信息：开始");
        TxnRespResult<GlInterfaceInfoRes> result = new TxnRespResult<>();
        try {
            result.getSuccess(glInterfaceService.getGlInterfaceInfoByPrimaryKey(id,tenantId,customerId));
        } catch (TxnException e) {
            logger.error("通过主键查询总账流水表信息:{}", e);
            result.getFail(e.getErrCode(), e.getErrMsg());
        }
        logger.debug("通过主键查询总账流水表信息： 结束");
        return result;
    }
}
